import 'package:flutter/material.dart';
import 'package:flutter_09_game/base/widget/base_get_builder.dart';
import 'package:flutter_09_game/config/app_color.dart';
import 'package:flutter_09_game/pages/game/game_detail/game_detail_logic.dart';
import 'package:flutter_09_game/pages/game/game_detail/game_detail_page/game_detail_page_logic.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/widget_bet_address.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/widget_bet_history_table.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/widget_bet_result.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/widget_history_table.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/widget_limit_bet_top.dart';
import 'package:flutter_09_game/pages/game/game_detail/widgets/widget_trend_chart.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'game_detail_transfer_logic.dart';

class GameDetailTransferPage extends StatelessWidget {
  GameDetailTransferPage({super.key, required this.gameLogic});

  final GameDetailLogic gameLogic;
  final GameDetailTransferLogic logic = Get.put(GameDetailTransferLogic());

  @override
  Widget build(BuildContext context) {
    return BaseGetBuilder<GameDetailTransferLogic>(
      backgroundColor: AppColor.pageBgColor,
      builder: (_) {
        return SingleChildScrollView(
            child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            12.verticalSpaceFromWidth,
            WidgetLimitBetTop(gameLogic: gameLogic,isPage: false,),
            8.verticalSpaceFromWidth,
            Container(
                margin: EdgeInsets.all(12.w).copyWith(top: 0),
                decoration: BoxDecoration(
                  color: AppColor.color121417, // 深色背景
                  borderRadius: BorderRadius.circular(8.w),
                ),
                padding: EdgeInsets.all(8.w),
                child: Column(
                  children: [
                    WidgetBetResult(gameLogic: gameLogic),
                    WidgetBetAddress(
                      logic: logic,
                      gameLogic: gameLogic,
                    )
                    // WidgetBetOperation(
                    //   gameLogic: gameLogic,
                    //   logic: logic,
                    // ),
                  ],
                )),

            WidgetTrendChart(
              gameLogic: gameLogic,
              scrollController: logic.scrollController,
              // height: 182.w,
            ),
            // 12.verticalSpaceFromWidth,
            // _buildOddEvenLayout(),
            8.verticalSpaceFromWidth,
            _buildHistoryTable(),
            8.verticalSpaceFromWidth,
            _buildBetHistoryTable(),
          ],
        ));
      },
    );
  }

  /// 构建历史记录表格
  Widget _buildHistoryTable() {
    return Obx(() {
      final historyList =
          Get.find<GameDetailLogic>().gameRoundRx.value.history ?? [];
      if (historyList.isEmpty) {
        return const SizedBox.shrink();
      }

      return HistoryTableWidget(
        historyList: historyList,
        onMoreTap: () => gameLogic.viewMoreHistory(),
      );
    });
  }

  /// 构建投注历史表格
  Widget _buildBetHistoryTable() {
    return Obx(() {
      final betHistoryList =
          Get.find<GameDetailLogic>().gameRoundRx.value.myHistory ?? [];

      // if (betHistoryList.isEmpty) {
      //   return const SizedBox.shrink();
      // }

      return BetHistoryTableWidget(
        betHistoryList: betHistoryList,
        onMoreTap: () => gameLogic.viewMoreRecordHistory(),
      );
    });
  }
}
